cmake_minimum_required(VERSION 3.8)
project(qt_ros2_gui)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
# find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

# 引入ROS 2库和Qt库
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(moveit_ros_planning_interface REQUIRED)
find_package(Qt5 REQUIRED Widgets)
find_package(path_plan REQUIRED)  # 添加 path_plan 作为依赖包
find_package(my_custom_msgs REQUIRED)


if(path_plan_FOUND)
        message("find the lib path_plan")
else()
        message("not find lib path_plan")
endif()

# 启用自动MOC
set(CMAKE_AUTOMOC ON)

# 创建可执行文件
add_executable(qt_ros2_gui_node src/qt_ros2_gui_node.cpp)
# 链接ROS 2和Qt库
ament_target_dependencies(qt_ros2_gui_node rclcpp std_msgs Qt5)

add_executable(interface_test src/interface_test.cpp)
ament_target_dependencies(interface_test rclcpp std_msgs Qt5 moveit_ros_planning_interface my_custom_msgs)

add_executable(third_party src/third_party.cpp)
ament_target_dependencies(third_party rclcpp std_msgs Qt5 moveit_ros_planning_interface my_custom_msgs)

add_executable(invoking_function_test src/invoking_function_test.cpp)
ament_target_dependencies(invoking_function_test rclcpp std_msgs Qt5 moveit_ros_planning_interface)

#####导入文件路径和动态库路径使用
target_include_directories(interface_test PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  ${path_plan_INCLUDE_DIRS})
ament_target_dependencies(
  interface_test
  "rclcpp"
  path_plan
)
#####导入文件路径和动态库路径使用
#####导入文件路径和动态库路径使用
target_include_directories(third_party PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  ${path_plan_INCLUDE_DIRS})
ament_target_dependencies(
  third_party
  "rclcpp"
  path_plan
)
#####导入文件路径和动态库路径使用
#####导入文件路径和动态库路径使用
target_include_directories(invoking_function_test PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  ${path_plan_INCLUDE_DIRS})
ament_target_dependencies(
  invoking_function_test
  "rclcpp"
  path_plan
)
#####导入文件路径和动态库路径使用

# 链接Qt库
target_link_libraries(qt_ros2_gui_node Qt5::Widgets)
target_link_libraries(interface_test Qt5::Widgets)
target_link_libraries(third_party Qt5::Widgets)
target_link_libraries(invoking_function_test Qt5::Widgets)

install(TARGETS qt_ros2_gui_node interface_test third_party invoking_function_test
  DESTINATION lib/${PROJECT_NAME})
  
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
